<!-- 页面名称 -->
<template>
	<view class="page-name">
		<u-navbar :is-back="true" title="公众号JSSDK"></u-navbar>
		<view></view>
	</view>
</template>

<script>
// #ifdef H5
import wechat from "@/static/js/wechat.js";
// #endif
var wx=null;
export default {
	data() {
		return { 
			options:{}
		}
	}, 
	onLoad(options) {
		this.options=options;
		var _this=this;
		wechat.initJssdk(function(jssdk){ 
			jssdk.ready(function(){
				wx=jssdk;
				console.log("I'm ready!"); 
				_this.getLocation();
			});
		},window.location.href)
	}, 
	onShow(){},
	onReachBottom(){},
	onHide(){}, 
	onReady(){},
	methods: {
		getLocation(){ 
			wx.getLocation({
				type: 'gcj02', // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
				success: function (res) {
				  console.log(res);
				_this.$hideLoading();
			    _this.latitude = res.latitude; // 纬度，浮点数，范围为90 ~ -90
			    _this.longitude = res.longitude; // 经度，浮点数，范围为180 ~ -180。
				_this.checkDistance();
				}
			});
		},
		applyPay(){//公众号支付
			var _this=this;
			if(this.order==null)return false;
			if(this.order!=null&&this.order.status==1){
				this.$toast("订单已支付，请勿重复操作");
				return false;
			}
			this.$showLoading("正在发起支付")
			this.$api.request({
				url:"/web/order/applyPay",
				data:{
					order_no:this.options.order_no 
				},
				success:function(res){ 
					if(res.code==200){
						wechat.wxpay(res.data,function(res){ 
							_this.$hideLoading();
							_this.$toast("支付成功",null,1500); 
							setTimeout(function(){ 
								uni.redirectTo({
									url:"/pages/user/signup"
								});
							},1000)
							 
						},function(){
							_this.$hideLoading();
							_this.$toast("支付失败"); 
						})
					}else{
						_this.$hideLoading()
						_this.$toast(res.msg);
					}
				}
			})
		}
	}
}

</script>

<style lang="scss">
	.page-name{ 
		
	}
</style>
